<h2><?php echo $heading_title; ?></h2>
<div class="accordion" id="accordion2">

  <?php foreach ($categories as $category) { ?>
  <div class="accordion-group">
    
    <div class="accordion-heading">
      <a class="pad" href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
      <?php if ($category['children']) { ?> 
      <a class="down" data-toggle="collapse" data-parent="#accordion2" href="#col<?php echo $category['category_id']; ?>"><i class='icon-chevron-down'></i></a>
      <?php } else {?>
      <?php } ?>
    </div>

    
    <div id="col<?php echo $category['category_id']; ?>" class="accordion-body collapse">
      <?php if ($category['children']) { ?>  
      <div class="accordion-inner">
          <ul>
            <?php foreach ($category['children'] as $child) { ?>
            <li>
              <?php if ($child['category_id'] == $child_id) { ?>
              <a href="<?php echo $child['href']; ?>" class="active"><?php echo $child['name']; ?></a>
              <?php } else { ?>
              <a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a>
              <?php } ?>
            </li>
            <?php } ?>
          </ul>
      </div>
      <?php } ?>
    </div>
  </div>
  <?php } ?>

</div>